import api from "../../http/api"  //套链接   获取请求

export default {
    //解决命名冲突
    namespaced: true,

    state: {
        pages: 0,
        total: 0,
        students: [],
        currentPage: 1,
        pageSize: 3,
        soso: {
            type: "name",
            value: ""
        },
    },
    //变化方法 用来设置state的方法，类似于组件中的methods
    mutations: {
        setState(state, newData) {
            state.pages = newData.pages;
            state.total = newData.total;
            state.students = newData.result;

        },
        addonePage(state, newData) {         
            state.currentPage = newData;
        },
        setPageSize(state, newData) {       
            state.pageSize = newData;  
        }


    },

    actions: {
        //获取学生数据  
        async getstudents(context) {
            const data = await api.students.getstudents();//收到api中的请求
            console.log(data);

            if (data.code) {
                context.commit("setState", //commit提交
                    data.data)
            }
        },

        //--------------删除学生数据-------------------
        async delstudent(context, _id) {
            const data = await api.students.delstudent({
                _id
            });
            console.log(data);

            if (data.code) {
                context.dispatch("getstudents")
            }
            console.log(data);
        },

        //--------------修改学生数据-------------------
        //先调用

        async getstudentbyId(context, _id) {
            const data = await api.students.getstudentbyId({
                _id
            });
            console.log('data', data);
            return data


        },
        async updateStudents(context, student) {

            const data = await api.students.updateStudents(student);
            if (data.code) {
                console.log(data);
                return data
            }
        }


    },
    modules: {},





}